import Vue from "vue";
import Router from "vue-router";
import store from './store/store';
import judgeURL from './store/judgeURL'
import storage from './store/localstorage'
import * as types from './store/types'
import Home from "./views/Home.vue";
import Search from "./views/Search";
import CityChoose from "./views/CityChoose";
import My from "./views/My";
import City from "./views/City";
import Show from "./views/Show";
import Showticket from "./views/Show-ticket";
import Showbuy from "./views/Show-buy";
import Showorder from "./views/Show-order";
import Comment from "./views/Comment";
import CommentAdd from "./views/Comment-add";
import PaySuccess from "./views/Pay-success";
import MyIntegral from "./views/My-integral";
import MyTicket from "./views/My-ticket";
import MyAdd from "./views/My-add";
import MyAddDiscount from "./views/My-add-discount";
import MyAddRecommend from "./views/My-add-recommend";
import MyCollect from "./views/My-collect";
import MyOrder from "./views/My-order";
import MyIncome from "./views/My-income";
import MyIncomeTotal from "./views/My-income-total";
import MyIncomeRecord from "./views/My-income-record";
import MyIncomeAuth from "./views/My-income-auth";
import MyIncomeRequest from "./views/My-income-request";
import MyLogin from "./views/My-login";
import MyRegPhone from "./views/My-reg-phone";
import MyRegPhoneCode from "./views/My-reg-phone-code";
import MyRegAgreement from "./views/My-reg-agreement";
import MyReg from "./views/My-reg";
import MyRegEmail from "./views/My-reg-email";
import MyRegEmailCode from "./views/My-reg-email-code";
import MyGetPassword from "./views/My-get-password";
import MyGetPasswordPhone from "./views/My-get-password-phone";
import MyGetPasswordPhoneCode from "./views/My-get-password-phone-code";
import MyGetPasswordSet from "./views/My-get-password-set";
import MyGetPasswordEmail from "./views/My-get-password-email";
import MyGetPasswordEmailCode from "./views/My-get-password-email-code";
import Guideline from "./views/Guideline";
import getthemegoods from "./views/getthemegoods";
import Article from "./views/Article";
import articleold from './views/articleold'
import ArticleComment from "./views/Article-comment";
import ArticleCommentAdd from "./views/Article-comment-add";
import MyProgram from "./views/My-program";
import MyProgramShow from "./views/My-program-show";
import MyProgramShowOrder from "./views/My-program-show-order";
import MyTicketOther from "./views/My-ticket-other";
import StripePay from "./views/Stripe-pay";
import MyOrderDetail from "./views/My-order-detail";
import MyOrderDetailUnpaid from "./views/My-order-detail-unpaid";
import Formulate from "./views/Formulate";
import FormulateOrigin from "./views/Formulate-origin";
import FormulateTarget from "./views/Formulate-target";
import FormulateDate from "./views/Formulate-date";
import FormulateSubmit from "./views/Formulate-submit";
import FormulateSuccess from "./views/Formulate-success";
import CommentSuccess from "./views/Comment-success";
import UserRecommend from "./views/User-recommend";
import MyFAQ from "./views/My-faq";
import MyTicketOtherFL from "./views/My-ticket-other-FL";
import AboutUs from './views/About-us';
import strategy from './views/strategy';
import Atrategy from './views/strategy';
import AtrategyArticle from './views/strategy-article';
import AtrategyCity from './views/strategy-city';
import GroupList from './views/GroupList';
import GroupShow from './views/GroupShow';
import GroupDetail from './views/GroupDetail';
import GroupShowOrder from './views/GroupShowOrder';
import GroupShowOrderDetailUnpaid from './views/GroupShowOrder-detail-unpaid';
import Redenvelope from "./views/Redenvelope";
import MyAdmin from "./views/My-admin";
/*用于测试*/
import mymap from './views/my-map.vue'
/*用于测试*/
Vue.use(Router);
const routes = [
    {
        path: "/",
        name: "home",
        meta: { title: "快帮行 - 玩点不一样"},
        component: Home
    },
    {
        path: "/search",
        name: "search",
        component: Search
    },
    {
        path: "/cityChoose",
        name: "cityChoose",
        component: CityChoose
    },
    {
        path: "/city",
        name: "city",
        component: City
    },
    {
        path: "/show/:id",
        name: "show",
        // meta: { requireAuth: true},
        component: Show
    },
    {
        path: "/show-ticket/:id",
        name: "show-ticket",
        component: Showticket
    },{
        path: "/show-buy/:id",
        name: "show-buy",
        meta: { requireAuth: true},
        component: Showbuy
    },{
        path: "/show-order",
        name: "show-order",
        meta: { requireAuth: true},
        component: Showorder
    },{
        path: "/comment/:goods_id",
        name: "comment",
        component: Comment
    },{
        path: "/comment-add/:order_id/:goods_id",
        name: "comment-add",
        meta: { requireAuth: true},
        component: CommentAdd
    },{
        path: "/pay-success",
        name: "pay-success",
        component: PaySuccess
    },{
        path: "/my-integral",
        name: "my-integral",
        component: MyIntegral
    },{
        path: "/my-ticket",
        name: "my-ticket",
        meta: { requireAuth: true},
        component: MyTicket
    },{
        path: "/my-add",
        name: "my-add",
        meta: { requireAuth: true},
        component: MyAdd
    },{
        path: "/my-collect",
        name: "my-collect",
        meta: { requireAuth: true},
        component: MyCollect
    },{
        path: "/my-order",
        name: "my-order",
        meta: { requireAuth: true},
        component: MyOrder
    },{
        path: "/my-income",
        name: "my-income",
        meta: { requireAuth: true},
        component: MyIncome
    },{
        path: "/my-income-total",
        name: "my-income-total",
        meta: { requireAuth: true},
        component: MyIncomeTotal
    },{
        path: "/my-income-record",
        name: "my-income-record",
        meta: { requireAuth: true},
        component: MyIncomeRecord
    },{
        path: "/my-income-auth",
        name: "my-income-auth",
        meta: { requireAuth: true},
        component: MyIncomeAuth
    },{
        path: "/my-income-request",
        name: "my-income-request",
        meta: { requireAuth: true},
        component: MyIncomeRequest
    },{
        path: "/my-login",
        name: "my-login",
        component: MyLogin
    },{
        path: "/my-reg-phone",
        name: "my-reg-phone",
        component: MyRegPhone
    },{
        path: "/my-reg-phone-code",
        name: "my-reg-phone-code",
        component: MyRegPhoneCode
    },{
        path: "/my-reg-agreement",
        name: "my-reg-agreement",
        component: MyRegAgreement
    },{
        path: "/my-reg",
        name: "my-reg",
        component: MyReg
    },{
        path: "/my-reg-email",
        name: "my-reg-email",
        component: MyRegEmail
    },{
        path: "/my-reg-email-code",
        name: "my-reg-email-code",
        component: MyRegEmailCode
    },{
        path: "/my-get-password",
        name: "my-get-password",
        component: MyGetPassword
    },{
        path: "/my-get-password-phone",
        name: "my-get-password-phone",
        component: MyGetPasswordPhone
    },{
        path: "/my-get-password-phone-code/:phone",
        name: "my-get-password-phone-code",
        component: MyGetPasswordPhoneCode
    },{
        path: "/my-get-password-set/:user",
        name: "my-get-password-set",
        component: MyGetPasswordSet
    },{
        path: "/my-get-password-email",
        name: "my-get-password-email",
        component: MyGetPasswordEmail
    },{
        path: "/my-get-password-email-code",
        name: "my-get-password-email-code",
        component: MyGetPasswordEmailCode
    },{
        path: "/my-program",
        name: "my-program",
        meta: { requireAuth: true},
        component: MyProgram
    },{
        path: "/my-admin",
        name: "my-admin",
        meta: { requireAuth: true},
        component: MyAdmin
    },{
        path: "/my-program-show/:id",
        name: "my-program-show",
        meta: { requireAuth: true},
        component: MyProgramShow
    },{
        path: "/MyProgramShowOrder",
        name: "MyProgramShowOrder",
        meta: { requireAuth: true},
        component: MyProgramShowOrder
    },{ //
        path: "/my-ticket-other",
        name: "my-ticket-other",
        meta: { requireAuth: true},
        component: MyTicketOther
    },
    {
        path: "/my",
        name: "my",
        meta: { requireAuth: true},
        component: My
    },
    {
        path: "/guideline",
        name: "guideline",
        component: Guideline
    },
    {
        path: "/getthemegoods/:id",
        name: "getthemegoods",
        component: getthemegoods
    },
    {
        path: "/article/:id",
        name: "article",
        component: Article
    },
    {
        path: "/article-comment/:id",
        name: "article-comment",
        component: ArticleComment
    },
    {
        path: "/article-comment-add/:id",
        name: "article-comment-add",
        meta: { requireAuth: true},
        component: ArticleCommentAdd
    },
    {
        path: "/stripe-pay",
        name: "stripe-pay",
        meta: { requireAuth: true},
        component: StripePay
    },
    {
        path: "/my-add-discount",
        name: "my-add--iscount",
        meta: { requireAuth: true},
        component: MyAddDiscount
    },
    {
        path: "/my-add-recommend",
        name: "my-add-recommend",
        meta: { requireAuth: true},
        component: MyAddRecommend
    },
    {
        path: "/my-order-detail/:id",
        name: "my-order-detail",
        meta: { requireAuth: true},
        component: MyOrderDetail
    },
    {
        path: "/my-order-detail-unpaid",
        name: "my-order-detail-unpaid",
        meta: { requireAuth: true},
        component: MyOrderDetailUnpaid
    },
    {
        path: "/formulate",
        name: "formulate",
        component: Formulate
    },
    {
        path: "/formulate-origin",
        name: "formulate-origin",
        component: FormulateOrigin
    },
    {
        path: "/formulate-target",
        name: "formulate-target",
        component: FormulateTarget
    },
    {
        path: "/formulate-date",
        name: "formulate-date",
        component: FormulateDate
    },
    {
        path: "/formulate-submit",
        name: "formulate-submit",
        component: FormulateSubmit
    },
    {
        path: "/formulate-success",
        name: "formulate-success",
        component: FormulateSuccess
    },
    {
        path: "/comment-success",
        name: "comment-success",
        component: CommentSuccess
    },
    {
        path: "/user-recommend",
        name: "user-recommend",
        component: UserRecommend
    },
    {
        path: "/faq",
        name: "my-faq",
        component: MyFAQ
    },
    {
        path: "/my-ticket-other-FL",
        name: "my-ticket-other-FL",
        component: MyTicketOtherFL
    },
    {
        path:"/About-us",
        name:"About-us" ,
        component:AboutUs
    },
    { //new新的攻略首页
        path:"/strategy",
        name:"strategy" ,
        component:Atrategy
    },
    { //老的攻略打开页面保留
        path: "/articleold",
        name: "articleold",
        component: articleold
    },
    { //new新的攻略城市列表页
        path:"/strategy-city",
        name:"strategy-city" ,
        component:AtrategyCity
    },
    { //new新的攻略详情页面
        path:"/strategy-article",
        name:"strategy-article" ,
        component:AtrategyArticle
    },
    { //new新的攻略详情页面
        path:"/my-map",
        name:"mymap" ,
        component:mymap
    }, { //拼游列表页面
        path:"/GroupList",
        name:"GroupList" ,
        component:GroupList
    },{ //拼游产品页面
        path:"/GroupShow",
        name:"GroupShow" ,
        component:GroupShow
    },{ //拼游详情页面
        path:"/GroupDetail",
        name:"GroupDetail" ,
        component:GroupDetail
    },{ //拼游填写信息页面
        path:"/GroupShowOrder",
        name:"GroupShowOrder" ,
        meta: { requireAuth: true},
        component:GroupShowOrder
    },{ //拼游未支付订单详情页面
        path:"/GroupShowOrder-detail-unpaid",
        name:"GroupShowOrder-detail-unpaid" ,
        component:GroupShowOrderDetailUnpaid
    },{ //红包领取
        path:"/Redenvelope",
        name:"Redenvelope" ,
        component:Redenvelope
    },


];


// 页面刷新时，重新赋值token
if (window.localStorage.getItem('token')) {
    store.commit(types.LOGIN, window.localStorage.getItem('token'))
}
// 页面刷新时，重新赋值appNestState
if (window.localStorage.getItem('appNestState')) {
    store.commit('setAppNestState', JSON.parse(localStorage.appNestState))
}
if(judgeURL.getUrl('partner_id')){ //获取URL飞拉参数
    window.localStorage.partner_id = judgeURL.getUrl('partner_id');
}
const router = new Router({
    //mode:'history',
    routes
});
router.beforeEach((to, from, next) => {
    if(window._hmt) {
        if(to.path) {
            window._hmt.push(['_trackPageview', '/quick_help_wap1/#' + to.fullPath]);
        }
    }
    if(to.name=='show'){
        if(to.query.hasOwnProperty('order_id')){
            window.localStorage.share_order_id = to.query.order_id;
        }
    }
    if(to.query.uid && to.query.uid>0){ //分享uid保存
        localStorage.uid=to.query.uid
    }
    /*if (to.meta.title) {//判断是否有标题
        document.title = to.meta.title
    }else{
        document.title = '快帮行 - 玩点不一样'
    }*/

    //判断是否是飞拉旅行
    if (storage.get('partner_id')=='fl') {
        //var partner_id = storage.get('partner_id') || null;
        document.title = '飞拉旅行 - 玩点不一样'
    }else{
        document.title = '快帮行-体验美好旅行生活'
    }


    if (to.matched.some(r => r.meta.requireAuth)) {


        if (store.state.token) {
            if(storage.get('partner_id')==""){
                window.localStorage.partner_id = judgeURL.getUrl('partner_id')||null
            }
            next();
        }
        else {
            next({
                path: '/my-login',
                query: {redirect: to.fullPath}
            })
        }
    }
    else {
        if(to.name=='my-login'){
            //console.log(from.fullPath)
            //console.log(to.fullPath)
            //window.localStorage.loginurl=to.query.redirect
            if(to.query.redirect != undefined){
                window.localStorage.loginurl=to.query.redirect
            }else{
                window.localStorage.loginurl=from.fullPath
            }

        }
        next();
    }
})
export default router;
